<!--
 * @Author: Chuckie
 * @Email: chuckie@aliyun.com
 * @Date: 2022-11-10 14:35:49
 * @LastEditTime: 2022-11-12 14:32:09
 * @Description: 
 * @FilePath: /zl-web/src/views/basic/enterprise/detail.vue
 *  
-->
<template>
  <div class="app-container">
    <el-form :model="state.form" label-width="120px">
      <el-form-item :label="$t('systemDept.table.shortName')">
        <el-input v-model="state.form.simpleName" />
      </el-form-item>
      <el-form-item :label="$t('systemDept.table.fullName')">
        <el-input v-model="state.form.fullName" />
      </el-form-item>
      <el-form-item :label="$t('systemDept.table.abbreviation')">
        <el-input v-model="state.form.insCode" />
      </el-form-item>


      <!-- <el-form-item label="版本">
        <el-input v-model="state.form.version" />
      </el-form-item> -->
      <el-form-item :label="$t('policy.table.order')">
        <el-input v-model="state.form.num" />
      </el-form-item>


      
      <el-form-item :label="$t('systemDept.table.type')">
        <el-radio-group v-model="state.form.type" class="ml-4">
          <el-radio label="1">公司</el-radio>
          <el-radio label="2">部门</el-radio>
        </el-radio-group>
      </el-form-item>
      
      <el-form-item :label="$t('systemDept.table.remark')">
        <el-input v-model="state.form.remark" />
      </el-form-item>
      <!-- <el-form-item label="关联公司编号">
        <el-input v-model="state.form.relCompanyNo" />
      </el-form-item>
      <el-form-item label="关联公司名称">
        <el-input v-model="state.form.relCompanyName" />
      </el-form-item> -->



      <el-form-item>
        <el-button type="primary" @click="onSubmit">{{$t('common.button.save')}}</el-button>
        <el-button @click="onCancel">{{$t('common.button.back')}}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang="ts">
import { create, select, selectOne, update } from './api/base-dept'
const route = useRoute()
const router = useRouter()

const { proxy }: any = getCurrentInstance()
const state = reactive({
  form: {
    id: '',
    simpleName: '',
    fullName: '',
    insCode: '',
    num: '',
    version: '',
    pid:'0',
    orderNum: '',
    remark: '',
    status: '',
    type: '',
    relCompanyNo: '',
    relCompanyName: '',
  },
  dictPolicy: { "0": '顶级权限' },
  dictPolicyType: {
    '0': '目录', '1': '菜单', '2': '按钮'
  },
  dictStatus: {
    1: '有效',
    2: '删除',
  }
})

const onCancel = () => {
  router.back()
}

const onSubmit = async () => {
  if (route.params.id) {
    const data = await update(state.form)
    proxy.$message({ message: proxy.$t('common.message.editSuccessfully'), type: 'success' })
  } else {
    state.form.pid = '0'
    const data = await create(state.form)
    proxy.$message({ message: proxy.$t('common.message.editSuccessfully'), type: 'success' })
  }
  router.back();

}

const onSelectOne = async (id: string) => {
  const data = await selectOne(id)
  state.form = { ...data.data }
  state.form.type = String(state.form.type)

}

const onSelect = async () => {
  const data = await select({ pageNum: 1, pageSize: 10000 })

}


onMounted(() => {
  onSelect()
  route.params.id && !Array.isArray(route.params.id) && onSelectOne(route.params.id)

})

</script>

<style lang="scss" scoped>
.el-input {
  width: 300px;
}

.el-select {
  width: 300px;
}

.el-textarea {
  width: 300px;
}
</style>
